package com.detection.dahua.demo.accesscontrol.application;

import com.dahuatech.hutool.http.Method;
import com.dahuatech.hutool.json.JSONUtil;
import com.dahuatech.icc.exception.ClientException;
import com.dahuatech.icc.oauth.model.v202010.OauthConfigUserPwdInfo;
import com.dahuatech.icc.oauth.utils.HttpUtils;
import com.detection.dahua.config.OauthConfigUtil;
import com.detection.dahua.model.accesscontrol.application.GenerateQRCodeResponse;
import lombok.extern.slf4j.Slf4j;

/**
 * program:java-sdk-demo
 *
 * @Author: 355079
 * @Date:2024-04-01 16:37
 * @Description: 门禁应用
 */
@Slf4j
public class ApplicationDemo {
    /**
     * 获取业主二维码字符串
     * @return
     */
    public String generateQRCode(String personCode){
        OauthConfigUserPwdInfo config = OauthConfigUtil.getOauthConfig();
        GenerateQRCodeResponse response=null;
        try {
            log.info("ApplicationDemo,generateQRCode,personCode:{}", personCode);
            String url = "/evo-apigw/evo-accesscontrol/1.0.0/card/card/generateQRCode/"+personCode;
            response = HttpUtils.executeJson(url, null,null, Method.GET , config, GenerateQRCodeResponse.class);
            log.info("ApplicationDemo,generateQRCode,response:{}", JSONUtil.toJsonStr(response));
        } catch (ClientException e) {
            log.error(e.getErrMsg(), e);
        }
        if(!response.isSuccess()) {
            log.info("获取业主二维码字符串失败:{}",response.getErrMsg());
            return null;
        }
        String code =response.getData();
        log.info("二维码字符串:{}",code);
        return code;
    }

}
